<?php
/**
 * template name: Search Deal Flight 
 * @author: Tham
 */
$textsearch = isset($_POST['textsearch']) ? ($_POST['textsearch']) : "";
get_header();

$paginator = new Paginator();
$scroll_page = 3;
$per_page = 8; //5 records/page
$current_page = isset($_GET['pg']) ? ($_GET['pg']) : 1;
$paper_url = '?pg=';
$inactive_page_tag = 'id="current_page"'; //id của thẻ span
$totalRecord = DealFlight::countSearchFlightTravel($textsearch);
//$totalRecord = $listcount[0]->total;
$next_page_text = '';
$previous_page_text = '';
$first_page_text = '';
$last_page_text = '';

$paginator->page_set($paper_url, $totalRecord[0]->total_design, $scroll_page, $per_page, $current_page, $inactive_page_tag, $next_page_text, $previous_page_text
        , $first_page_text, $last_page_text);

//$listAllDeals = DealFlight::getAllbyIdCat(DealFlight::DEAL, $paginator->start, $paginator->per_page, $id_cat);
$listAllSearch = DealFlight::SearchFlightTravel($textsearch, $paginator->start, $paginator->per_page);
$frist_deal = $listAllSearch[0];
// print_r($frist_deal);
?>

<div class="content">
    <div class="container">

        
        <?php
        if($frist_deal <> "")
        {
                ?>
                <div class="sli-deal">
                    <div class="price-deal">€ <?php echo number_format($frist_deal->price); ?></div>
                    <img src="<?php echo DEAL_URL . $frist_deal->image ?>"   />
                    <div class="text-sli">
                        <h1><?php echo $frist_deal->name_deal; ?> <span>On Sale</span> </h1>
                        <h4>Exclusive Deals-up to <?php echo $frist_deal->discount ?>% Off</h4>
                    </div>
                </div>
                 <?php
        }
       else
            {
                ?>
                  Not Found Information
                <?php
               
            }
        ?>

        <div class="row">

            <?php
            if($listAllSearch <> "")
            {
            $i = 1;
            foreach ($listAllSearch as $rows) {
                if($i !== 0)
                {

                $type_travel = $rows->type_travel;

                if ($type_travel == DealFlight::DEAL) {

                    $url_detail = get_site_url() . '/detail-deal?i=' . $rows->deal_flight_id;

                    $img_url = DEAL_URL . $rows->image;
                } else {
                    $url_detail = get_site_url() . '/flight-detail?i=' . $rows->deal_flight_id;
                    $img_url = FLIGHT_URL . $rows->image;
                }
                ?>
                <div class="col-md-6">
                    <div class="box-deal">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="price-deal price-small">€<?php echo number_format($rows->price); ?></div>
                                <img src="<?php echo TIMTHUMB_URL ?>?src=<?php echo DEAL_URL . $rows->image ?>&w=219&h=194"/>
                            </div>
                            <div class="col-md-6">
                                <h4><a href="#"><?php echo $rows->name; ?></a></h4>
                                <p>
                                    <?php
                                    $description = $rows->description;
                                    $description = explode("<!--more-->", $description);
                                    echo $description[0];

                                    //  echo Helper::SubStrText($description, 200) ;                        
                                    ?>
                                </p>
                                <a href="<?php echo get_site_url(); ?>/detail-deal?i=<?php echo $rows->deal_flight_id; ?>" class="btn btn-primary">Show deal</a>
                            </div>
                        </div>
                    </div><!--box-deal-->
                </div><!--col-md-6-->

                <?php
                }
                
                $i++;
            }
            }
            
            ?>




        </div><!--row-->
        <br clear="all" />
        <div style="text-align: center;">
            <?php
            echo $paginator->previous_page . "         ";
            echo $paginator->next_page;
            ?>
        </diV>

    </div><!--container-->
</div><!--content-->
<?php get_footer(); ?>
